package com.ulife.order.components;


import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.dubbo.rpc.RpcContext;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.google.common.base.Strings;
import com.ulife.base.entities.order.*;
import com.ulife.base.logics.order.*;
import com.ulife.base.logics.order.cms.order.dto.PageList;
import com.ulife.base.logics.order.cms.order.dto.SoCancelbillVO;
import com.ulife.common.gateway.utils.annotation.ApiParameter;
import com.ulife.common.gateway.utils.define.CommonParameter;
import com.ulife.common.gateway.utils.define.Version;
import com.ulife.common.gateway.utils.entity.ServiceException;
import com.ulife.common.utils.lang.JsonMapper;
import com.ulife.common.utils.lang.StringUtils;
import com.ulife.member.api.MemberService;
import com.ulife.member.api.response.customer.CustomerDto;
import com.ulife.order.api.OrderCmsService;
import com.ulife.order.api.OrderService;
import com.ulife.order.api.core.refund.RefundBillStatus;
import com.ulife.order.api.core.refund.RefundStatus;
import com.ulife.order.api.core.refund.RefundWay;
import com.ulife.order.api.errors.OrderErrorCodes;
import com.ulife.order.api.request.cms.GetRefundBillsRequest;
import com.ulife.order.api.request.cms.SoCancelbillReq;
import com.ulife.order.api.response.ResponseMessage;
import com.ulife.order.api.response.SoRefundBillInfo;
import com.ulife.order.api.response.SoRefundBillsInfo;
import com.ulife.order.api.response.cms.SoCancelbillDTO;
import com.ulife.order.api.response.cms.SoCancelbillListResponse;
import com.ulife.order.components.core.refund.OrderRefund;
import com.ulife.order.components.core.result.BaseResult;
import com.ulife.order.components.core.result.ResultCode;
import com.ulife.order.components.mode.ItemStockDTO;
import com.ulife.order.components.core.cancel.OrderCancel;
import com.ulife.order.service.enumeration.SaleOrderPayStatus;
import com.ulife.order.service.enumeration.SaleOrderStatus;
import com.ulife.stock.api.StockService;
import com.ulife.stock.api.response.ProductStockResponse;
import com.ulife.stock.api.response.ProductsStockResponse;
import org.apache.ibatis.session.RowBounds;
import org.dozer.DozerBeanMapper;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.annotation.Resource;
import java.util.*;

/**
 * Created by Ulife on 2016/5/31.
 */
@Component
@Service(version = Version.LATEST)
public class OrderCmsComponent implements OrderCmsService {

    @Resource
    SaleOrderLogic saleOrderLogic;

    @Resource
    SoCancelBillLogic soCancelBillLogic;

    @Resource
    SoRefundBillLogic soRefundBillLogic;

    @Resource
    OrderCancel orderCancel;

    @Resource
    OrderRefund orderRefund;

    @Resource
    SaleOrderItemLogic saleOrderItemLogic;

    @Reference(version = Version.LATEST)
    StockService stockService;

    @Reference(version = Version.LATEST)
    MemberService memberService;

    @Resource
    DozerBeanMapper dozerBeanMapper;

    @Resource
    SoCommentsLogic soCommentsLogic;

    private static JsonMapper Json = JsonMapper.nonDefaultMapper();
    Logger logger = LoggerFactory.getLogger(OrderService.class);

    //region 订单方法
    /**
     * 根据订单号获取订单信息
     *
     * @param sale_no
     * @return
     */
    private SaleOrder getOrderBySo(String sale_no) {
        SaleOrderCriteria saleOrderCriteria = new SaleOrderCriteria();
        saleOrderCriteria.createCriteria().andSaleNoEqualTo(sale_no);
        List<SaleOrder> saleOrderList = saleOrderLogic.list(saleOrderCriteria);
        SaleOrder saleOrder = saleOrderList.size() > 0 ? saleOrderList.get(0) : null;
        return saleOrder;
    }

    /**
     * 根据订单号获取商品信息
     *
     * @param sale_no
     * @return
     */
    private List<SaleOrderItem> getOrderItemList(String sale_no) {
        SaleOrderItemCriteria saleOrderItemCriteria = new SaleOrderItemCriteria();
        saleOrderItemCriteria.createCriteria().andSoNoEqualTo(sale_no);
        return saleOrderItemLogic.list(saleOrderItemCriteria);
    }

    //endregion

    //region 库存操作
    /**
     * 修改库存字符串
     *
     * @param saleOrderItemList
     * @return
     */
    private String getStockStr(List<SaleOrderItem> saleOrderItemList) {
        List<ItemStockDTO> itemStockDTOs = new ArrayList<ItemStockDTO>();
        if (saleOrderItemList != null && saleOrderItemList.size() > 0) {
            for (SaleOrderItem saleOrderItem : saleOrderItemList) {
                ItemStockDTO itemStockDTO = new ItemStockDTO();
                itemStockDTO.setId(saleOrderItem.getItemId());
                itemStockDTO.setNum(saleOrderItem.getQuantity());
                itemStockDTOs.add(itemStockDTO);
            }
        }
        return Json.toJson(itemStockDTOs);
    }

    /**
     * 取消库存
     */
    private void rollbackStock(String sale_no) throws ServiceException {
        List<SaleOrderItem> list = getOrderItemList(sale_no);
        if (list != null) {
            rollbackStock(list);
        }
    }
    /**
     * 释放库存
     *
     * @param saleOrderItemList
     */
    private HashMap<String, String> rollbackStock(List<SaleOrderItem> saleOrderItemList) {
        HashMap<String, String> rsMap = new HashMap<String, String>();

        String StockStr = getStockStr(saleOrderItemList);
        if (StockStr == null || StockStr.isEmpty()) {
            rsMap.put("status", "false");
            rsMap.put("code", "NoStockStr");
            rsMap.put("msg", "[退回库存|退回库存 in 退回库存方法] 报错 code= NoStockStr");
            logger.error("[退回库存|退回库存 in 退回库存方法] 报错 code= NoStockStr");
            return rsMap;
        }

        ProductsStockResponse productsStockResponse;
        try {
            productsStockResponse = stockService.rollbackStock(StockStr);
        } catch (Exception ex) {
            rsMap.put("status", "false");
            rsMap.put("code", "NoStockStr");
            rsMap.put("msg", "【库存服务|还原库存 in 还原库存方法】 报错 msg=" + ex.getMessage());
            logger.error("【库存服务|还原库存 in 还原库存方法】 报错 msg=" + ex.getMessage());
            logger.error("【报错信息】 StockStr=" + StockStr);
            logger.error(ex);
            return rsMap;
        }

        boolean stockStatus = true;
        long productid = 0;

        if (productsStockResponse != null && productsStockResponse.getProductsStock() != null && productsStockResponse.getProductsStock().size() > 0) {

            for (ProductStockResponse productStockResponse : productsStockResponse.getProductsStock()) {
                if (productStockResponse.getStock() < 0) {
                    stockStatus = false;
                    productStockResponse.getId();
                    break;
                }
            }
        }

        if (!stockStatus) {
            rsMap.put("status", "false");
            rsMap.put("code", "ServiceError");
            rsMap.put("msg", "【库存服务|还原库存 in 还原库存方法】 报错 code=ServiceError");
            logger.error("【库存服务|还原库存 in 还原库存方法】 报错 code=ServiceError");
            logger.error("【报错信息】 StockStr=" + StockStr);
            return rsMap;
        }
        rsMap.put("status", "true");
        return rsMap;
    }
    //endregion

    //region 订单管理
    /**
     * 中台订单取消
     * @param sale_no
     * @param operator_id
     * @return
     * @throws ServiceException
     */
    @Override
    public ResponseMessage cmsOrderCancel( String sale_no,long operator_id, int operationType,String cancelType, String cancelReason,String cancelRemark,int isNeedRefund) throws ServiceException
    {
        ResponseMessage rtn = new ResponseMessage();
        rtn.isSuccess=false;

        //判断订单是否存在
        SaleOrder order = getOrderBySo(sale_no);
        if (order == null) {
            rtn.setMessage("订单号不存在");
            logger.warn("客服取消订单时，订单号不存在；sale_no = " + sale_no);
            return rtn;
        }
        //判断订单状态
        if(!order.getPayType().equals("线上支付")&& !order.getPayStatus().equals(SaleOrderPayStatus.Paid.value()))
        {
            rtn.setMessage("订单支付方式为线上支付,且支付状态为 [未支付或部分支付] 的才能操作取消.");
            logger.warn("客服取消订单时，订单支付方式或支付状态有误；sale_no = " + sale_no);
            return rtn;
        }
        if(!order.getStatus().equals(SaleOrderStatus.Created.value()) && !order.getStatus().equals(SaleOrderStatus.Confirmed.value()))
        {
            rtn.setMessage("订单状态有误.[已创建或已确认] 的才能操作取消.");
            logger.warn("客服取消订单时，订单状态有误；sale_no = " + sale_no);
            return rtn;
        }

        try {
            cmsCancelOrder(order, operator_id, operationType, cancelType, cancelReason, cancelRemark, isNeedRefund);
        }
        catch (ServiceException ex)
        {
            logger.error("[订单管理|取消订单] 异常，异常信息："+ ex.toString());
            return rtn;
        }
        rtn.isSuccess=true;
        return rtn;
    }

    /***
     *
     * @param order
     * @param operator_id
     * @throws ServiceException
     */
    @Transactional
    private void cmsCancelOrder(SaleOrder order,long operator_id,int operationType, String cancelType,String cancelReason,String cancelRemark,int isNeedRefund)throws ServiceException
    {
        try {
            //生成取消单据
            boolean cancelflag=orderCancel.createSoCancelBilll(order, operator_id, operationType, cancelType, cancelReason, cancelRemark, isNeedRefund);
            if(!cancelflag)
            {
                throw new ServiceException(OrderErrorCodes.errorCodes_ORDER_CANCEL_CreateBill_ERROR,"[订单服务]创建取消单据失败.");
            }
            //更新订单状态
            order.setStatus(SaleOrderStatus.Cancel.value());
            order.setModifiedBy(Long.toString(operator_id));
            order.setModifiedTime(new Date());
            saleOrderLogic.updateSelective(order);

            //库存退还
            rollbackStock(order.getSaleNo());

        }catch (ServiceException ex)
        {
            logger.error(ex.getMessage() + "                 " + order.getSaleNo());
            throw new ServiceException(OrderErrorCodes.errorCodes_ORDER_CANCEL_PARAMETER_ERROR,"[订单服务]订单取消失败.");
        }

    }
    //endregion

    //region 订单取消单据

    @Override
    public SoCancelbillListResponse getSoCancelBillList(@ApiParameter(required = false, name = "query", defaultValue = "", desc = "Json字符串") String query,
                                                        @ApiParameter(required = false, name = "page", desc = "页码", defaultValue = "1") int page,
                                                        @ApiParameter(required = false, name = "rows", desc = "每页条数", defaultValue = "20") int rows) throws ServiceException {

        SoCancelbillReq queryParams = new SoCancelbillReq();
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);

        if (!StringUtils.isEmpty(query)) {
            try {
                queryParams = mapper.readValue(query, SoCancelbillReq.class);
            } catch (Exception ex) {
                ex.printStackTrace();
                logger.error(ex.getMessage() + "                 " + query);
                throw new ServiceException(OrderErrorCodes.errorCodes_ORDER_CANCEL_PARAMETER_ERROR,"[订单服务]获取订单取消单据列表参数错误.");
            }
        }
        SoCancelbillVO itemQueryVo=new SoCancelbillVO();
        dozerBeanMapper.map(queryParams,itemQueryVo);
        itemQueryVo.setPageno(page);
        itemQueryVo.setPagesize(rows);

        SoCancelbillListResponse listResponse = new SoCancelbillListResponse();
        PageList<SoCancelBill> _page = soCancelBillLogic.queryCancelBillList(itemQueryVo);
        List<SoCancelbillDTO> billls=new ArrayList<>();
        if(_page!=null && _page.getList()!=null){
            for (SoCancelBill item:_page.getList()){
                SoCancelbillDTO billDto=new SoCancelbillDTO();
                dozerBeanMapper.map(item,billDto);
                billDto.setCreatetime(item.getCreateTime().getTime());
                billDto.setModifytime(item.getModifyTime().getTime());
                billls.add(billDto);
            }
        }
        listResponse.setBillLists(billls);
        listResponse.setTotal(_page != null ? _page.getTotal() : 0);
        return  listResponse;
    }

    //endregion

    //region 退款单据
    @Override
    public boolean processSoCancelBill(String cancelBillNo)
            throws ServiceException {
        String userId = RpcContext.getContext().getAttachment(CommonParameter.userId);
        Long operator = Long.valueOf(userId);
        if(operator== null){
            throw new ServiceException(OrderErrorCodes.errorCodes_REFUNDBILL_PROCESS_PARAM_ERROR, "ordercmsservice.processRefundBill 用户Id错误");
        }

        try {
            SoCancelBillCriteria soCancelBillCriteria = new SoCancelBillCriteria();
            soCancelBillCriteria.createCriteria()
                    .andCancelBillNoEqualTo(cancelBillNo);

            List<SoCancelBill> soCancelBillList = soCancelBillLogic.list(soCancelBillCriteria);
            if (soCancelBillList == null || soCancelBillList.size() == 0) {
                throw new ServiceException(OrderErrorCodes.errorCodes_SOCANNELBILL_NOTFOUND_ERROR, "ordercmsservice.processSoCancelBill");
            }
            SoCancelBill soCancelBill = soCancelBillList.get(0);
            //判断单据状态
            BaseResult baseResult = orderCancel.ProcessSoCancelBill(soCancelBill,operator);
            if (baseResult.getCode() == ResultCode.Success) {
                return true;
            }else{
                throw new ServiceException(OrderErrorCodes.errorCodes_SOCANNELBILL_PROCESS_ERROR, baseResult.getMessage());
            }
        } catch (Exception ex) {
            throw new ServiceException(OrderErrorCodes.errorCodes_SOCANNELBILL_PROCESS_ERROR, ex.getMessage());
        }
    }

    @Override
    public SoRefundBillsInfo getRefundBillList(
            String condition
            , int page
            , int rows)
            throws ServiceException {
        SoRefundBillsInfo result = new SoRefundBillsInfo();
        result.setItems(new ArrayList<SoRefundBillInfo>());
        try {
            GetRefundBillsRequest conditionInfo = Json.fromJson(condition, GetRefundBillsRequest.class);
            SoRefundBillCriteria soRefundBillCriteria = new SoRefundBillCriteria();
            SoRefundBillCriteria.Criteria criteria = soRefundBillCriteria.createCriteria();
            if (conditionInfo != null) {
                Date createStartTime = new Date(), createEndTime = new Date(), refundStartTime = new Date(), refundEndTime = new Date();
                createStartTime.setTime(conditionInfo.getCreatedStartTime());
                createEndTime.setTime(conditionInfo.getCreatedEndTime());
                refundStartTime.setTime(conditionInfo.getRefundStartTime());
                refundEndTime.setTime(conditionInfo.getRefundEndTime());

                if (!Strings.isNullOrEmpty(conditionInfo.getRefundBillNo()))
                    criteria.andRefundBillNoEqualTo(conditionInfo.getRefundBillNo());
                if (!Strings.isNullOrEmpty(conditionInfo.getSoNo()))
                    criteria.andSoNoEqualTo(conditionInfo.getSoNo());
                if (conditionInfo.getStatus() > 0)
                    criteria.andStatusEqualTo(conditionInfo.getStatus());
                if (!Strings.isNullOrEmpty(conditionInfo.getChannel()))
                    criteria.andRefundChannelEqualTo(conditionInfo.getChannel());
                if (!criteria.isValid()) {
                    //如果没有查询条件，如果没有指定查询范围，默认一周查询范围
                    if (createStartTime.getTime() == 0) {
                        Calendar now = Calendar.getInstance();
                        now.add(Calendar.DAY_OF_YEAR, -7);
                        createStartTime = now.getTime();
                    }
                }
                // YYYY-MM-dd  23:59:59
                Calendar calendar = Calendar.getInstance();
                if (createEndTime.getTime() != 0) calendar.setTime(createEndTime);
                calendar.set(Calendar.HOUR, 23);
                calendar.set(Calendar.MINUTE, 59);
                calendar.set(Calendar.SECOND, 59);
                createEndTime = calendar.getTime();
                if (createStartTime.getTime() != 0) criteria.andCreateTimeBetween(createStartTime, createEndTime);

                if (refundStartTime.getTime() != 0){
                    if (refundEndTime.getTime() != 0) {
                        calendar.setTime(refundEndTime);
                    }else{
                        calendar.setTime(new Date());
                    }
                    calendar.set(Calendar.HOUR, 23);
                    calendar.set(Calendar.MINUTE,59);
                    calendar.set(Calendar.SECOND, 59);
                    refundEndTime = calendar.getTime();
                    criteria.andModifyTimeBetween(refundStartTime, refundEndTime);
                }else if(refundEndTime.getTime() != 0){
                    criteria.andModifyTimeLessThanOrEqualTo(refundEndTime);
                }
            }
            //分页默认值
            if (page == 0) {
                page = 1;
            }
            if (rows == 0) {
                rows = 20;
            }
            RowBounds rowBounds = new RowBounds((Math.max(1, page) - 1) * rows, rows);
            List<SoRefundBill> soRefundBills = soRefundBillLogic.listEx(soRefundBillCriteria, rowBounds);
            int totalCount = soRefundBillLogic.count(soRefundBillCriteria);
            //for dbEntity - > dto
            if (soRefundBills != null && soRefundBills.size() > 0) {
                for (SoRefundBill dbEntity : soRefundBills) {
                    SoRefundBillInfo info = new SoRefundBillInfo();
                    dozerBeanMapper.map(dbEntity, info);
                    if (dbEntity.getCreateTime() != null)
                        info.setCreateTime(dbEntity.getCreateTime().getTime());
                    if (dbEntity.getModifyTime() != null)
                        info.setModifyTime(dbEntity.getModifyTime().getTime());
                    result.getItems().add(info);
                }
                result.setCount(totalCount);
            }
        } catch (Exception ex) {
            throw new ServiceException(OrderErrorCodes.errorCodes_REFUNDBILL_GETLIST_ERROR, ex.getMessage());
        }
        return result;
    }

    @Override
    public SoRefundBillInfo getRefundBill(String refundBillNo)
            throws ServiceException {
        SoRefundBillInfo result = new SoRefundBillInfo();
        try {
            SoRefundBillCriteria soRefundBillCriteria = new SoRefundBillCriteria();
            soRefundBillCriteria.createCriteria()
                    .andRefundBillNoEqualTo(refundBillNo);

            List<SoRefundBill> soRefundBills = soRefundBillLogic.list(soRefundBillCriteria);
            if (soRefundBills == null || soRefundBills.size() == 0) {
                throw new ServiceException(OrderErrorCodes.errorCodes_REFUNDBILL_NOTFOUND_ERROR, "ordercmsservice.getRefundBill");
            }
            dozerBeanMapper.map(soRefundBills.get(0), result);
        } catch (Exception ex) {
            throw new ServiceException(OrderErrorCodes.errorCodes_REFUNDBILL_GET_ERROR, ex.getMessage());
        }
        return result;
    }

    @Override
    public boolean processRefundBill(
            String refundBillNo
            , String data)
            throws ServiceException {
        try {
            //传参
            String userId = RpcContext.getContext().getAttachment(CommonParameter.userId);
            SoRefundBillInfo soRefundBillInfo = Json.fromJson(data, SoRefundBillInfo.class);

            Long operator = Long.valueOf(userId);
            if(operator== null){
                throw new ServiceException(OrderErrorCodes.errorCodes_REFUNDBILL_PROCESS_PARAM_ERROR, "ordercmsservice.processRefundBill 用户Id错误");
            }
            //验证
            SoRefundBillCriteria soRefundBillCriteria = new SoRefundBillCriteria();
            soRefundBillCriteria.createCriteria()
                    .andRefundBillNoEqualTo(refundBillNo);

            List<SoRefundBill> soRefundBills = soRefundBillLogic.list(soRefundBillCriteria);
            if (soRefundBills == null || soRefundBills.size() == 0) {
                throw new ServiceException(OrderErrorCodes.errorCodes_REFUNDBILL_NOTFOUND_ERROR, "ordercmsservice.processRefundBill");
            }
            SoRefundBill soRefundBill = soRefundBills.get(0);
            if(soRefundBill.getStatus() != RefundBillStatus.Created.value()){
                throw new ServiceException(OrderErrorCodes.errorCodes_REFUNDBILL_PROCESS_ERROR, "退款单据状态不正确");
            }

            //赋值
            if (soRefundBillInfo != null) {
                if (!Strings.isNullOrEmpty(soRefundBillInfo.getRefundType()))
                    soRefundBill.setRefundType(soRefundBillInfo.getRefundType());
                if (!Strings.isNullOrEmpty(soRefundBillInfo.getRefundWay()))
                    soRefundBill.setRefundWay(soRefundBillInfo.getRefundWay());
                if (!Strings.isNullOrEmpty(soRefundBillInfo.getRefundChannel()))
                    soRefundBill.setRefundChannel(soRefundBillInfo.getRefundChannel());
                if (!Strings.isNullOrEmpty(soRefundBillInfo.getRefundSerialNumber()))
                    soRefundBill.setRefundSerialNumber(soRefundBillInfo.getRefundSerialNumber());
                if (!Strings.isNullOrEmpty(soRefundBillInfo.getRefundBankSerialNumber()))
                    soRefundBill.setRefundBankSerialNumber(soRefundBillInfo.getRefundBankSerialNumber());
            }
            /*
            private double refundAmount; 暂时不支持部分退款
            */
            BaseResult<RefundStatus> result = orderRefund.doRefund(soRefundBill, operator);

            if (result.getCode().value() > 0) {
                //so_no ->customer_id -> 手机号
                SaleOrderCriteria saleOrderCriteria = new SaleOrderCriteria();
                saleOrderCriteria.createCriteria()
                        .andSaleNoEqualTo(soRefundBill.getSoNo());
                List<SaleOrder> saleOrders = saleOrderLogic.list(saleOrderCriteria);
                if(saleOrders != null && saleOrders.size() > 0){
                    CustomerDto customerDto = memberService.getCustomerById(saleOrders.get(0).getCustomerId().toString());
                    if (customerDto != null && !Strings.isNullOrEmpty(customerDto.getMobileNo())) {
                        memberService.sendSMS_Normal(customerDto.getMobileNo(), result.getMessage());
                    }
                }
                return true;
            }else {
                throw new ServiceException(OrderErrorCodes.errorCodes_REFUNDBILL_PROCESS_ERROR, result.getMessage());
            }
        } catch (Exception ex) {
            throw new ServiceException(OrderErrorCodes.errorCodes_REFUNDBILL_PROCESS_ERROR, ex.getMessage());
        }
    }
    //endregion

    //region 订单备注
    /**
     *  添加订单备注
     * @param order_no 订单编号(长度50)
     * @param type 备注类型（长度50）
     * @param order_status 订单状态
     * @param pay_status 支付状态
     * @param comment 备注（长度255）
     * @param created_by 创建人
     */
    @Override
    public boolean addSaleOrderComment(String order_no, String type, int order_status, int pay_status,String comment,
                                       long created_by ) throws ServiceException{

        if (Strings.isNullOrEmpty(order_no)){
            throw new ServiceException(OrderErrorCodes.errorCodes_ArgumentFormat_ERROR,"订单号不能为空");
        }
        if(Strings.isNullOrEmpty(comment)){
            throw new ServiceException(OrderErrorCodes.errorCodes_ArgumentFormat_ERROR,"备注内容不能为空");
        }
        if(created_by <= 0){
            throw new ServiceException(OrderErrorCodes.errorCodes_ArgumentFormat_ERROR,"创建人不能为空");
        }

        boolean isExist = this.isOrderExist(order_no);
        if(!isExist){
            throw new ServiceException(OrderErrorCodes.errorCodes_ORDER_NOT_FOUND,"订单不存在");
        }

        SoComments soComment = new SoComments();
        soComment.setSoNo(order_no);
        soComment.setType(type);
        soComment.setCreator(created_by);
        soComment.setCreateTime(new Date());
        soComment.setPayStatus(pay_status);
        soComment.setOrderStatus(order_status);
        soComment.setRemark(comment);

        long  insertedItemId = soCommentsLogic.insertSelective(soComment);
        if(insertedItemId > 0)
            return true;
        else
            return false;
    }

    /**
     *  校验订单是否存在
     * @param order_no 订单编号
     * @return true:存在订单；<br />false：不存在此订单；
     */
    private boolean isOrderExist(String order_no){
        SaleOrderCriteria criteria = new SaleOrderCriteria();
        criteria.createCriteria().andSaleNoEqualTo(order_no);
        int count = saleOrderLogic.count(criteria);
        if(count > 0)
            return  true;
        else
            return  false;
    }
    //endregion
}